/*
 * Copyright 2011 CraneLeeon authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.crane.webtemplate.model;

import java.io.InputStream;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.Date;
import org.hibernate.Hibernate;

/**
 *
 * @author CraneLeeon
 */
public class ImageFile extends BO{
    
    private String code;
    
    private String name;
    
    private String type;
    
    private Date dtt_create;
    
    private Date dtt_update;
    
    protected Blob binaryData;
    
    protected Long size = Long.valueOf(0);
    
    protected Blob thumbnail;
    
    protected Long thumbnailSize = Long.valueOf(0);

    public Blob getBinaryData() {
        return binaryData;
    }

    public void setBinaryData(Blob binaryData) {
        this.binaryData = binaryData;
    }
    
    public InputStream getInputStream() throws Exception {
        if(this.binaryData == null) return null;
        return this.binaryData.getBinaryStream();
    }

    public void setInputStream(InputStream inputfile) throws Exception{
        this.binaryData = Hibernate.createBlob(inputfile);
    }
    

    public Blob getThumbnail() {
        return thumbnail;
    }

    public void setThumbnail(Blob thumbnail) {
        this.thumbnail = thumbnail;
    }
    
    public InputStream getThumbnailInputStream() throws SQLException{
        if(this.thumbnail == null) return null;
        return this.thumbnail.getBinaryStream();
    }
    
    public void setThumbnailInputStream(InputStream inputfile) throws Exception{
        this.thumbnail = Hibernate.createBlob(inputfile);
    }

    public Long getThumbnailSize() {
        return thumbnailSize;
    }

    public void setThumbnailSize(Long thumbnailSize) {
        this.thumbnailSize = thumbnailSize;
    }

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Date getDtt_create() {
        return dtt_create;
    }

    public void setDtt_create(Date dtt_create) {
        this.dtt_create = dtt_create;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Date getDtt_update() {
        return dtt_update;
    }

    public void setDtt_update(Date dtt_update) {
        this.dtt_update = dtt_update;
    }
    
}
